﻿@{
    ViewBag.Title = "UndulyIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var _State = -1, OrganizeId = "", RoomId = "";
    $(function () {
        InitialPage();
        GetGrid();
        GetTree();
    })
   
    function InitialPage() {
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);

            }, 200);
            e.stopPropagation();

        });
        
        //初始化时间

        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            description: "=选择=",
            click: function (item) { 
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
    }

    function GetTree() {
        var item = {
            height: $(window).height() - 55,
            url: "../../QualificationManage/Contract/GetUndulyCountTreeListTojson?OrganizeId=" + OrganizeId,
            onnodeclick: function (item) {
                switch (item.id) {
                    case "All":
                        _State = -1;
                        break; 
                    case "UnHandled":
                        _State = 2;
                        break;
                    case "Current":
                        _State = 3;
                        break; 
                    case "Complete":
                        _State = 5;
                        break; 
                    default: break;  
                }
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        var queryJson = {
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val(),
            Name: $("#Name").val(),
            Code: $("#Code").val(),
            State: _State,
            OrganizeId: OrganizeId,
            RoomId: RoomId,
            SourceType: 2
        };
        $gridTable.jqGrid({
            url: "../../QualificationManage/RentContract/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: "主键", name: "id", hidden: true },
                { label: "三方编号", name: "sourceid", hidden: true },
                { label: "合同编号", name: "code", index: "code", width: 240, align: "center", sortable: false },
                {
                    label: "签约时间", name: "signdate", index: "signdate", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        var msg = cellvalue;
                        if (rowObject.state == 1 || rowObject.state == "1") {
                            msg = "<span  style='background-color:#B05B5C' class='label '>未签约</span>";
                        }
                        if (cellvalue == null && rowObject.state != 1) {
                            msg = "";
                        }
                        return msg;
                    }
                },
                { label: "租赁房产", name: "allname", index: "allname", width: 200, align: "center", sortable: false },
                {
                    label: "签约主体", name: "signtype", index: "signtype", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        var Msg = "";
                        switch (cellvalue) {
                            case 0:
                            case "0":
                            case "1":
                            case 1: Msg = "单位";
                                break;
                            case "2":
                            case 2: Msg = "个人";
                                break;
                            default: Msg = "---";
                                break;
                        }
                        return Msg;
                    }
                },
                { label: "入住人ID", name: "liveinuserid", hidden: true },
                { label: "入住人姓名", name: "name", index: "name", width: 200, align: "center", sortable: false },
                { label: "所属单位", name: "companyname", index: "companyname", width: 200, align: "center", sortable: false },
                {
                    label: "起始日期", name: "begindate", index: "begindate", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }

                },
                {
                    label: "终止日期", name: "enddate", index: "enddate", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                { label: "月租金", name: "monthlyrent", index: "monthlyrent", width: 200, align: "center", sortable: false },
                { label: "押金", name: "deposit", index: "deposit", width: 200, align: "center", sortable: false },
                { label: "备注", name: "description", index: "description", width: 200, align: "center", sortable: false }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'Code',
            sortorder: 'desc',
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $('#btn_Reset').trigger("click");
            $(".ui-filter-text").trigger("click");
        });
        $("#btn_Reset").click(function () { 
            $("#Name").val("");
            $("#Code").val("");
            $("#IDCard").val("");
            $("#PStruct").val(""); 
        }) 
    }
    function SearchEvent()
    {
        var queryJson = {
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val(),
            Name: $("#Name").val(),
            Code: $("#Code").val(),
            IDCard: $("#IDCard").val(),
            PStruct: $("#PStruct").val(),
            State: _State,
            OrganizeId: OrganizeId,
            RoomId: RoomId,
            SourceType: 2
        };
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../QualificationManage/RentContract/GetPagList",
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }
    function btn_detail() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (checkedRow(keyValue)) {
            top.tablist.newTab({
                id: "UndulyForm",
                title: '过渡合同',
                closed: true,
                icon: "fa fa-wrench",
                url: top.contentPath + '/QualificationManage/Contract/UndulyFormBussiness?keyValue=' + keyValue
            });
        } 
    } 
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel"> 
            <div class="panel-Title" style="padding:0px; text-align:center;">合同状态</div>
            <div id="itemTree1"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search ">
                    <table>
                        <tr>
                            <td>签约日期</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">签约日期：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day).AddMonths(1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">姓名：</td>
                                                <td class="formValue">
                                                    <input id="Name" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">合同编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">身份证号：</td>
                                                <td class="formValue">
                                                    <input id="IDCard" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">租赁房产：</td>
                                                <td class="formValue">
                                                    <input id="PStruct" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr> 
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td> 
                        </tr> 
                    </table> 
                </div> 
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default " onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-detail" class="btn btn-default " onclick="btn_detail()"><i class="fa fa-eye"></i>&nbsp;查看</a> 
                    </div> 
                </div>
            </div> 
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div> 
        </div>
    </div>
</div>



